﻿namespace Nello
{
    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;

    public class Util
    {
        public static T GetEnum<T>(object enumobj)
        {
            return (T) Enum.Parse(typeof(T), enumobj.ToString(), true);
        }

        public static List<string> GetGroupValues(string text, string pattern)
        {
            List<string> list = new List<string>();
            Match match = Regex.Match(text, pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
            foreach (Group grp in match.Groups)
            {
                list.Add(grp.Value);
            }
            return list;
        }

        public static bool IsChinese(string inputstr)
        {
            Regex regex = new Regex(@"^[\u4e00-\u9fa5]+$");
            return regex.IsMatch(inputstr);
        }

        public static bool IsGuid(string s)
        {
            try
            {
                Guid g = new Guid(s);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static string NewGuid()
        {
            return Guid.NewGuid().ToString("N");
        }
    }
}

